<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .list{
            height: 150px;
            overflow-y: auto;
            width: 100px;
        }
        .news{
            height: 30px;
        }
    </style>
</head>
<body>
    <div id="test"></div>
    <script src="../lib2/react.development.js"></script>
    <!-- //引入核心库 -->
    <script src="../lib2//react-dom.development.js"></script>
    <!-- //支持react的dom操作 -->
    <script src="../lib/babel.min.js"></script>
    <!-- lib2中的babel版本太高了 -->
    <script type="text/babel">
        class MyComponent extends React.Component{
        //    static getDerivedStateFromProps(props,state){
        //        //该生命周期基本不用
        //        const {a}=state
        //         console.log('getDerivedStateFormProps,需要加static表示类的实例',props,state)
        //         //返回一个state的值后更改里面的值数据也不会改变(替代了以前componentwillreceive)
        //         //props是更改的值但是你想改state里面的值还是取决于你返回的state对象
        //         return {a:22}
        //         //可以返回null不做手脚(必须返回state对象)
        //     }
            constructor(){
                super()
                this.state={a:1,newArr:[]}
                console.log('constructor')
            }
            add=()=>{
                const {a}=this.state
                this.setState({a:a+1})
            }
            getSnapshotBeforeUpdate(){
                return this.state.a//返回更新前的a(该函数的意思是更新前的快照,即保留更新前的数据)
            }
            componentDidUpdate(preProps,preState){
                console.log(preProps,preState)//拿到更新前的state和状态
                console.log(this.state.a)
            }
            componentDidMount(){
          
            }
            render(){
                return(
                    <div>
                        <button onClick={this.add}>点我加1</button>
                        <div className="list" ref='list'>
                           
                          </div>
                        </div>
                )
            }
        }
        ReactDOM.render(<MyComponent name='邹'/>,document.getElementById('test'))
        </script>
</body>
</html>